package mvp.com.bbc.viewpagerlayoutmanager;

import android.view.View;

/**
 * Created by ${cbf} on 2017/11/30.
 */

public class BottmTopLayoutManager extends ViewPagerLayoutManager {
    private int itemSpace;
    private float minScale;
    private float moveSpeed;

    public BottmTopLayoutManager(int itemSpace) {
        this(new Builder(itemSpace));
    }

    public BottmTopLayoutManager(int itemSpace, float minScale, float moveSpeed) {
        this(new Builder(itemSpace).setMinScale(minScale).setMoveSpeed(moveSpeed));
    }

    public BottmTopLayoutManager(Builder builder) {
        this(builder.itemSpace, builder.moveSpeed, builder.minScale, builder.reverseLayout);
    }

    public BottmTopLayoutManager(int itemSpace, float moveSpeed, float minScale, boolean reverseLayout) {
        super(HORIZONTAL, reverseLayout);
        this.itemSpace = itemSpace;
        this.minScale = minScale;
        this.moveSpeed = moveSpeed;
    }

    public int getItemSpace() {
        return itemSpace;
    }

    public void setItemSpace(int itemSpace) {
        this.itemSpace = itemSpace;
    }

    public float getMinScale() {
        return minScale;
    }

    public void setMinScale(float minScale) {
        assertInLayoutOrScroll(null);
        if (this.minScale == minScale) return;
        this.minScale = minScale;
        removeAllViews();
    }

    public float getMoveSpeed() {
        return moveSpeed;
    }

    public void setMoveSpeed(float moveSpeed) {
        assertInLayoutOrScroll(null);
        if (this.moveSpeed == moveSpeed) return;
        this.moveSpeed = moveSpeed;
        requestLayout();
    }

    @Override
    protected float setInterval() {
        return mDecoratedMeasurement;
    }

    @Override
    protected void setItemViewProperty(View itemView, float targetOffset) {
        itemView.setRotationY(calrotat(targetOffset));

    }

    private float calrotat(float targetOffset) {
        return 0;
    }

    public void setOrientation(int orientation) {
        super.setOrientation(orientation);
    }

    @Override
    protected float setViewElevation(View itemView, float targetOffset) {
        return itemSpace/targetOffset*5;
    }

    @Override
    protected void setUp() {
        super.setUp();
    }

    public static class Builder {
        private static final float DEFAULT_SPEED = 1f;
        private static final float MIN_SCALE = 0.5f;

        private int itemSpace;
        private int orientation;
        private float minScale;
        private float moveSpeed;
        private boolean reverseLayout;

        public Builder(int itemSpace) {
            this.itemSpace = itemSpace;
            this.minScale = MIN_SCALE;
            this.moveSpeed = DEFAULT_SPEED;
            reverseLayout = false;
        }

        public Builder setItemSpace(int itemSpace) {
            this.itemSpace = itemSpace;
            return this;
        }

        public Builder setOrientation(int orientation) {
            this.orientation = orientation;
            return this;
        }

        public Builder setMinScale(float minScale) {
            this.minScale = minScale;
            return this;
        }

        public Builder setMoveSpeed(float moveSpeed) {
            this.moveSpeed = moveSpeed;
            return this;
        }

        public Builder setReverseLayout(boolean reverseLayout) {
            this.reverseLayout = reverseLayout;
            return this;
        }

        public BottmTopLayoutManager build() {
            return new BottmTopLayoutManager(this);
        }

    }
}
